package com.odriver.neulearn.Activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.odriver.neulearn.R;
import com.odriver.neulearn.Util.ScreenUtil;
import com.odriver.neulearn.Util.TransferUtil;

public class CourseDetail extends AppCompatActivity implements View.OnClickListener {

    private TextView topic, courseNum, courseTime, videoNum, testNum, courseDay, people, detail;
    private TextView courseID, confirm, courseDetail;
    private ImageView imageView;
    private int code = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ScreenUtil.setScreenNoTitle(this);
        setContentView(R.layout.activity_course_detail);
        initView();
    }

    /**
     * 初始化控件 + initViewData() 初始化信息
     */
    public void initView() {
        imageView = (ImageView) findViewById(R.id.idp_course_menu_listview_pic);
        courseID = (TextView) findViewById(R.id.idp_course_menu_listview_id);
        topic = (TextView) findViewById(R.id.idp_course_menu_listview_topic);
        courseNum = (TextView) findViewById(R.id.idp_course_menu_listview_classNum);
        courseTime = (TextView) findViewById(R.id.idp_course_menu_listview_classTime);
        videoNum = (TextView) findViewById(R.id.idp_course_menu_listview_videoNum);
        testNum = (TextView) findViewById(R.id.idp_course_menu_listview_classTest);
        courseDay = (TextView) findViewById(R.id.idp_course_menu_listview_classDayNum);
        people = (TextView) findViewById(R.id.idp_course_menu_listview_personNum);
        detail = (TextView) findViewById(R.id.idp_course_menu_listview_info);
        courseDetail = (TextView) findViewById(R.id.idp_course_menu_listview_detail);
        confirm = (TextView) findViewById(R.id.idp_course_menu_listview_confrim);
        courseDetail.setOnClickListener(this);
        confirm.setOnClickListener(this);
        initViewData();
    }

    public void initViewData() {
        Bundle bundle = this.getIntent().getExtras();
        TransferUtil.getBitmap(this, bundle.getString("url"), imageView);
        code = bundle.getInt("courseID");
        courseID.setText("课程ID：" + code);
        topic.setText(bundle.getString("topic"));
        courseNum.setText("课程数目：" + bundle.getInt("courseNum"));
        courseTime.setText("课程学时：" + bundle.getInt("courseTime"));
        videoNum.setText("视频总数：" + bundle.getInt("video"));
        testNum.setText("课程测验：" + bundle.getInt("test"));
        courseDay.setText("课程天数：" + bundle.getInt("courseDay"));
        people.setText("参课人数：" + bundle.getInt("people"));
        detail.setText(bundle.getString("detail"));
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            /**
             *
             */
            case R.id.idp_course_menu_listview_confrim: {

                break;
            }
            /**
             * 详细信息页面
             */
            case R.id.idp_course_menu_listview_detail: {
                Intent intent = new Intent(CourseDetail.this, MainActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("id", "" + code);
                intent.putExtras(bundle);
                startActivity(intent);
                finish();
                break;
            }
        }
    }
}
